package types

import (
	bytes "bytes"
	database_sql_driver "database/sql/driver"
	errors "errors"

	github_com_go_courier_enumeration "github.com/go-courier/enumeration"
)

var InvalidPlatformType = errors.New("invalid PlatformType type")

func ParsePlatformTypeFromLabelString(s string) (PlatformType, error) {
	switch s {
	case "":
		return PLATFORM_TYPE_UNKNOWN, nil
	case "iot平台":
		return PLATFORM_TYPE__IOT, nil
	case "视频平台":
		return PLATFORM_TYPE__VIDEO, nil
	}
	return PLATFORM_TYPE_UNKNOWN, InvalidPlatformType
}

func (v PlatformType) String() string {
	switch v {
	case PLATFORM_TYPE_UNKNOWN:
		return ""
	case PLATFORM_TYPE__IOT:
		return "IOT"
	case PLATFORM_TYPE__VIDEO:
		return "VIDEO"
	}
	return "UNKNOWN"
}

func ParsePlatformTypeFromString(s string) (PlatformType, error) {
	switch s {
	case "":
		return PLATFORM_TYPE_UNKNOWN, nil
	case "IOT":
		return PLATFORM_TYPE__IOT, nil
	case "VIDEO":
		return PLATFORM_TYPE__VIDEO, nil
	}
	return PLATFORM_TYPE_UNKNOWN, InvalidPlatformType
}

func (v PlatformType) Label() string {
	switch v {
	case PLATFORM_TYPE_UNKNOWN:
		return ""
	case PLATFORM_TYPE__IOT:
		return "iot平台"
	case PLATFORM_TYPE__VIDEO:
		return "视频平台"
	}
	return "UNKNOWN"
}

func (v PlatformType) Int() int {
	return int(v)
}

func (PlatformType) TypeName() string {
	return "demo/device-hub/constants/types.PlatformType"
}

func (PlatformType) ConstValues() []github_com_go_courier_enumeration.IntStringerEnum {
	return []github_com_go_courier_enumeration.IntStringerEnum{PLATFORM_TYPE__IOT, PLATFORM_TYPE__VIDEO}
}

func (v PlatformType) MarshalText() ([]byte, error) {
	str := v.String()
	if str == "UNKNOWN" {
		return nil, InvalidPlatformType
	}
	return []byte(str), nil
}

func (v *PlatformType) UnmarshalText(data []byte) (err error) {
	*v, err = ParsePlatformTypeFromString(string(bytes.ToUpper(data)))
	return
}

func (v PlatformType) Value() (database_sql_driver.Value, error) {
	offset := 0
	if o, ok := (interface{})(v).(github_com_go_courier_enumeration.DriverValueOffset); ok {
		offset = o.Offset()
	}
	return int64(v) + int64(offset), nil
}

func (v *PlatformType) Scan(src interface{}) error {
	offset := 0
	if o, ok := (interface{})(v).(github_com_go_courier_enumeration.DriverValueOffset); ok {
		offset = o.Offset()
	}

	i, err := github_com_go_courier_enumeration.ScanIntEnumStringer(src, offset)
	if err != nil {
		return err
	}
	*v = PlatformType(i)
	return nil
}
